<?php

/**
 * GamesController - The controller for Games class
 *
 * @author
 * @version
 */

require_once 'Zend/Controller/Action.php';

class Adminb_GamesController extends Zend_Controller_Action
{



	public function init(){

		$member=new CMember();

		if(!$member->isUser($this->_request->getModuleName(),$this->_request->getControllerName())){


				$this->_redirect(MY_URL.'/auth-login?preurl='.CURRENT_URL);


		}

	}

	public function preDispatch()
	{

		$this->view->addHelperPath(MY_ROOT.'/vhelpers');

		Zend_Controller_Action_HelperBroker::addPath(MY_ROOT.'/chelpers');

	}


    public function indexAction()
    {
        //
    }


    public function dobetcAction()
    {

        $this->_helper->viewRenderer->setNoRender();

    	if(!$this->getRequest()->isPost()){

            $this->view->showMsg("发生未知错误!");

            return false;
        }
        
        $paramArray=$this->_request->getParams();

        $member=new CMember();
        
        $integral =$member->getintegral($_COOKIE[COOKIE_PRE.'uid']);
        if($integral[0]['integral'] == 0 || $integral[0]['integral'] < $paramArray['chips']){

            $this->view->showMsg("您的积分不足!");

            return false;
        }else{
            $this->view->assign('integral',$integral[0]['integral']);
        }
        $filters = array(
            '*'   => 'StringTrim'
        );

        $validators = array(
        );

        $input = new Zend_Filter_Input($filters, $validators, $paramArray);
        
        //
        $fbbet=new CGamefbbet();
        $data=array(
            'uid'=>$_COOKIE[COOKIE_PRE.'uid'],
            'chips'=>$input->chips,
            'suppout_team'=>$input->suppout_team,
            'sceneid'=>$input->sceneid,
            'add_time'=>time(),
         );
        if($fbbet->createFbbet($data)){
            //如果下注成功，则扣除对应会员积分
            $member->updateIntegral($input->chips,$_COOKIE[COOKIE_PRE.'uid']);
        }
        /*插入数据到下注表 end*/

        $this->view->showMsg("您已成功下注，为避免透支，系统已暂时扣除您$input->chips积分!",'games-index');

        return true;
    }


}
